package com.senseuni.common.dialog.indicator;

import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.animation.LinearInterpolator;

public class BallScaleRippleMultipleIndicator extends BallScaleMultipleIndicator{

    @Override
    public void draw(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(3);
        super.draw(canvas, paint);
    }

    @Override
    public void createAnimation() {
        long[] delays=new long[]{0, 200, 400};

        for (int i = 0; i < 3; i++) {
            final int index=i;
            ValueAnimator scaleAnim=ValueAnimator.ofFloat(0,1);
            scaleAnim.setInterpolator(new LinearInterpolator());
            scaleAnim.setDuration(1000);
            scaleAnim.setRepeatCount(-1);
            scaleAnim.addUpdateListener(animation -> {
                scaleFloats[index] = (Float) animation.getAnimatedValue();
                postInvalidate();
            });
            scaleAnim.setStartDelay(delays[i]);
            scaleAnim.start();
            addAnimator(scaleAnim);

            ValueAnimator alphaAnim=ValueAnimator.ofInt(0,255);
            scaleAnim.setInterpolator(new LinearInterpolator());
            alphaAnim.setDuration(1000);
            alphaAnim.setRepeatCount(-1);
            alphaAnim.addUpdateListener(animation -> {
                alphaInts[index] = (Integer) animation.getAnimatedValue();
                postInvalidate();
            });
            scaleAnim.setStartDelay(delays[i]);
            alphaAnim.start();
            addAnimator(alphaAnim);
        }
    }

}
